<?php

     session_start();
     include('common.php');
     include('../includes/SmartCode.js');

    if (session_is_registered(MySBB_Admin_username) and $member_permission == 1)
    {

// **  **

         if ($groupper_row['admincp_adminads'] != 1)
         {
             $SF->error('المعذره .. هذه الميزه غير متاحه لك !');
         }

// **  **

         if ($_GET['add'] == 1)
         {
             if ($_GET['index'] == 1)
             {
                 $smiles_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "smiles WHERE smile_type='0' ORDER BY id ASC LIMIT 0,13");

                 $smiles_row = array();
                 while ($smile_row = $DB->sql_fetch_array($smiles_query))
                 {
                     $smiles_row[] = $smile_row;
                     $Smarty->assign('smiles_row',$smiles_row);
                 }

                 $SF->Make_cplink_path('<a href="announcement.php?main=1">الاعلانات الاداريه</a> -> اضافة اعلان اداري');
                 $Smarty->display('announcement_add.tpl');
             }

             if ($_GET['start'] == 1)
             {
                 if (empty($_POST['T1']) or empty($_POST['S1']))
                 {
                     $SF->error('يرجى تعبئة كافة المعلومات');
                 }

                 $insert = $DB->sql_query("INSERT INTO " . $db_prefix . "announcement(id,title,text,writer,date) VALUES('NULL','" . $_POST['T1'] . "','" . $_POST['S1'] . "','" . $_COOKIE['MySBB_Admin_username'] . "','" . $date . "')");
                 if ($insert)
                 {
                     $SF->msg('تم كتابة الاعلان بنجاح !');
                     $SF->go_to('announcement.php?main=1',2);
                 }
             }
         }

// **  **

         if ($_GET['main'] == 1)
         {
             $get_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "announcement ORDER BY id DESC");

             $announcement_row = array();
             while ($get_row = $DB->sql_fetch_array($get_query))
             {
                 $announcement_row[] = $get_row;
                 $Smarty->assign('announcement_row',$announcement_row);
             }

             $SF->Make_cplink_path('الاعلانات الاداريه');
             $Smarty->display('announcement_main.tpl');
         }

// **  **

         if ($_GET['edit'] == 1)
         {
             if ($_GET['index'] == 1)
             {
                 $get_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "announcement WHERE id='" . intval($_GET['id']) . "'");
                 $get_row   = $DB->sql_fetch_array($get_query);

                 $text = str_replace('<br />','',$get_row['text']);

                 $smiles_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "smiles WHERE smile_type='0' ORDER BY id ASC LIMIT 0,13");

                 $smiles_row = array();
                 while ($smile_row = $DB->sql_fetch_array($smiles_query))
                 {
                     $smiles_row[] = $smile_row;
                     $Smarty->assign('smiles_row',$smiles_row);
                 }

                 $Smarty->assign('text',$text);
                 $Smarty->assign_by_ref('get_row',$get_row);

                 $Smarty->display('announcement_edit.tpl');
             }

             if ($_GET['start'] == 1)
             {
                 if (empty($_POST['T1']) or empty($_POST['S1']))
                 {
                     $SF->error('يرجى تعبئة كافة المعلومات');
                 }

                 $insert = $DB->sql_query("UPDATE " . $db_prefix . "announcement SET title='" . $_POST['T1'] . "',text='" . $_POST['S1'] . "',writer='" . $SF->SafeSQL($member_row['username']) . "' WHERE id='" . intval($_GET['id']) . "'");
                 if ($insert)
                 {
                     $SF->msg('تم التحديث بنجاح !');
                     $SF->go_to('announcement.php?main=1',2);
                 }
             }
         }

// **  **

         if ($_GET['del'] == 1)
         {
             $del = $DB->sql_query("DELETE FROM " . $db_prefix . "announcement WHERE id='" . intval($_GET['id']) . "'");
             if ($del)
             {
                 $SF->msg('تم الحذف بنجاح !');
                 $SF->go_to('announcement.php?main=1',2);
             }
         }

// **  **

    }

?>